import Vue from 'vue';

const modal = Vue.extend(require('./modal.vue').default);
let instance;
let timeOut;
let tips= {
  open(options) {
    if (!instance) {
      instance = new modal({
      });
    }
    if (instance.visible) {
      clearTimeout(timeOut);
      this.close();
    }
    if (typeof options === 'string') {
      instance.text = options;
    } 
    instance.vm = instance.$mount()
    document.getElementById("app").appendChild(instance.vm.$el);

    Vue.nextTick(() => {
      instance.visible = true;
    });
    timeOut = setTimeout(()=>{
        this.close();
    },2000)
  },

  close() {
    if (instance) {
      Vue.nextTick(() => {
        instance.visible = false;
      });
    }
  }
};
export default tips; 